package mysql

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"os"
)

var DB *xorm.Engine

func Install() error {
	mode := os.Getenv("MODE")

	var sourceName = "root:password@tcp(39.101.140.145:30005)/glue?charset=utf8&loc=Local"
	if mode == "prod" {
		url := os.Getenv("SQL_URL")
		sourceName = "root:password@tcp(" + url + ")/glue?charset=utf8&loc=Local"
	}

	db, err := xorm.NewEngine("mysql", sourceName)
	if err != nil {
		return err
	}

	db.ShowSQL(true)

	DB = db
	return nil
}
